﻿using System;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using BG.Data;
using Kwan.Data;
using Kwan.Web;
using System.ComponentModel;
using BG.Service.Ext;
using Kwan.Helper.Strings;

namespace BG.Service
{
    public class Callback
    {

        public Callback() { }

        //#region 桌面
        //[Description("返回当前用户的菜单权限")]
        //public string GetPageMenuView(NameValueCollection ps)
        //{
        //    var list = PageAuthority.GetTestList();

        //    var result = new List<PageAuthorityTree>();

        //    recursion(new PageAuthorityTree { id = "0", children = new List<PageAuthorityTree>() }, result, list);
        //    return JSON.Serialize(result);
        //}
        ////递归
        //private void recursion(PageAuthorityTree parentNode, IList<PageAuthorityTree> result, IList<PageAuthority> list)
        //{
        //    var items = from c in list where c.Parent == parentNode.id select c;
        //    foreach (var item in items)
        //    {
        //        var child = new PageAuthorityTree
        //        {
        //            name = item.Text,
        //            code = item.Code,
        //            area = item.Area,
        //            controller = item.Controller,
        //            action = item.Action,
        //            indexField = item.IndexField,
        //            isDisable = item.IsDisable,
        //            isHide = item.IsHide,
        //            icon1 = item.IconCss16,
        //            icon2 = item.IconCss24,
        //            icon3 = item.IconCss48,
        //            winId = item.PageId,
                    
        //            id = item.Id,
        //            text = item.Text,
        //            leaf = item.IsLeaf,
        //            children = new List<PageAuthorityTree>(),
        //            level = item.NodeLevel,
        //            treeid = item.TreeIds
        //        };
        //        if (item.Parent == "0")
        //        {
        //            result.Add(child);
        //        }
        //        else
        //        {
        //            parentNode.children.Add(child);
        //        }
        //        recursion(child, result, list);
        //    }
        //}
        
        //[Description("用户所有的菜单权限不包含弄到快捷方式里的")]
        //public string GetAllPageWithOutShortcut(NameValueCollection ps)
        //{
        //    var result = PageAuthority.GetTestList()
        //        .Where(t => t.IsLeaf == true)
        //        .ToList();
        //    return JSON.Serialize(result);
        //}
        //[Description("返回当前用户的快捷方式")]
        //public string GetCurrentUserShortcuts(NameValueCollection ps)
        //{
        //    var pList = PageAuthority.GetTestList();
        //    var result = from p in pList
        //                 where p.IsLeaf == true
        //                 select new MyShortcut { Page = p, PageId = p.PageId };

        //    return JSON.Serialize(result.ToList());
        //}
        //[Description("添加快捷方式")]
        //public string AddShortcut(NameValueCollection ps)
        //{
        //    //MyShortcut entity = new MyShortcut();
        //    //LoadEntity(e => entity.User = e, SysUserRepository.Load, new CurrentUser().UserInfo.Id);
        //    //LoadEntity(e => entity.Page = e, PageAuthorityRepository.Load, Request["Page.Id"]);
        //    //MyShortcutRepository.SaveOrUpdate(entity);
        //    return JSON.Serialize(JSON.ExtResult("true", string.Empty));
        //}

        //[Description("删除快捷方式")]
        //public string DelShortcut(NameValueCollection ps)
        //{
        //    //MyShortcutRepository.Delete(id());
        //    return JSON.Serialize(JSON.ExtResult("true", string.Empty));
        //}
        //#endregion

        //#region 修改密码
        //public string EditPassword(NameValueCollection ps)
        //{
        //    TUser u = ConfigManager.Instance.IndentityUser();
        //    if (u != null && MD5.Md5Decrypt(u.Password) == ps["oldPwd"])
        //    {
        //        u.Password = MD5.Md5Encrypt(ps["newPwd"]);
        //        DBContext.Save(u);
        //        return JSON.ExtResult("true", "\"ok\"");
        //    }
        //    return JSON.ExtResult("false", "\"false\"");
        //}
        //#endregion

        //#region 修改密码
        //public string Logout(NameValueCollection ps)
        //{
        //    TUser u = ConfigManager.Instance.IndentityUser();
        //    if (u != null)
        //    {
        //        UserUtil.Logout();
        //        return JSON.ExtResult("true", "\"ok\"");
        //    }
        //    return JSON.ExtResult("false", "\"false\"");
        //}
        //#endregion

        //#region 系统配置
        //public string Configuration(NameValueCollection ps)
        //{
        //    BaseFacade<TConfig, TConfig> facade = new BaseFacade<TConfig, TConfig>();
        //    facade.QueryBuilder = new ConfigQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 房间类别
        //public string RoomClass(NameValueCollection ps)
        //{
        //    BaseFacade<TRoomClass, TRoomClass> facade = new BaseFacade<TRoomClass, TRoomClass>();
        //    facade.QueryBuilder = new RoomClassQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //public string RoomClassTree(NameValueCollection ps)
        //{
        //    IList<TRoomClass> list = new Expression().List<TRoomClass>(TRoomClass.sort.Desc);
        //    IList<TRoomClass> parent = list.Where(a => a.Pid == 0).ToList();
        //    IList<ClassTree> treeList = new List<ClassTree>();
        //    CreatedTree(treeList, null, parent);
        //    return JSON.Serialize(treeList);
        //}
        //private void CreatedTree(IList<ClassTree> tree, ClassTree node, IList<TRoomClass> parent)
        //{
        //    foreach (TRoomClass p in parent)
        //    {
        //        if (p.Pid == 0)
        //        {
        //            var child = parent.Where(a => a.Pid == p.EntityID);
        //            node = SetNode(p, false);
        //            node.children = new List<ClassTree>();
        //            if (child.Count() > 0)
        //            {
        //                CreatedTree(tree, node, child.ToList());
        //            }
        //            else
        //            {
        //                node.leaf = true;
        //            }
        //            tree.Add(node);
        //        }
        //        else
        //        {
        //            if (node.children == null)
        //            {
        //                node.children = new List<ClassTree>() { SetNode(p, true) };
        //            }
        //            else
        //            {
        //                node.children.Add(SetNode(p, true));
        //            }
        //        }
        //    }
        //}
        //private ClassTree SetNode(TRoomClass t, bool isLeaf)
        //{
        //    ClassTree node = new ClassTree();
        //    node.expanded = true;
        //    node.isChecked = false;
        //    node.id = t.EntityID.ToString();
        //    node.leaf = isLeaf;
        //    node.text = t.NameCN;
        //    return node;
        //}
        //#endregion

        //#region 房间
        //public string Room(NameValueCollection ps)
        //{
        //    BaseFacade<TRoom, VRoom> facade = new BaseFacade<TRoom, VRoom>();
        //    facade.QueryBuilder = new RoomQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 物品类别
        //public string ProductClass(NameValueCollection ps)
        //{
        //    BaseFacade<TProductClass, TProductClass> facade = new BaseFacade<TProductClass, TProductClass>();
        //    facade.QueryBuilder = new RoomClassQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //public string ProductClassTree(NameValueCollection ps)
        //{
        //    IList<TProductClass> list = new Expression().List<TProductClass>(TProductClass.sort.Desc);
        //    IList<TProductClass> parent = list.Where(a => a.Pid == 0).ToList();
        //    IList<ClassTree> treeList = new List<ClassTree>();
        //    CreatedTree(treeList, null, parent);
        //    return JSON.Serialize(treeList);
        //}
        //private void CreatedTree(IList<ClassTree> tree, ClassTree node, IList<TProductClass> parent)
        //{
        //    foreach (TProductClass p in parent)
        //    {
        //        if (p.Pid == 0)
        //        {
        //            var child = parent.Where(a => a.Pid == p.EntityID);
        //            node = SetNode(p, false);
        //            node.children = new List<ClassTree>();
        //            if (child.Count() > 0)
        //            {
        //                CreatedTree(tree, node, child.ToList());
        //            }
        //            else
        //            {
        //                node.leaf = true;
        //            }
        //            tree.Add(node);
        //        }
        //        else
        //        {
        //            if (node.children == null)
        //            {
        //                node.children = new List<ClassTree>() { SetNode(p, true) };
        //            }
        //            else
        //            {
        //                node.children.Add(SetNode(p, true));
        //            }
        //        }
        //    }
        //}
        //private ClassTree SetNode(TProductClass t, bool isLeaf)
        //{
        //    ClassTree node = new ClassTree();
        //    node.expanded = true;
        //    node.isChecked = false;
        //    node.id = t.EntityID.ToString();
        //    node.leaf = isLeaf;
        //    node.text = t.NameCN;
        //    return node;
        //}
        //#endregion

        //#region 物品
        //public string Product(NameValueCollection ps)
        //{
        //    BaseFacade<TProduct, VProduct> facade = new BaseFacade<TProduct, VProduct>();
        //    facade.QueryBuilder = new ProductQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 角色树
        //public string Role(NameValueCollection ps)
        //{
        //    BaseFacade<TRole, TRole> facade = new BaseFacade<TRole, TRole>();
        //    facade.QueryBuilder = new RoleQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //public string Permit(NameValueCollection ps)
        //{
        //    string moduleID = ps["moduleID"];
        //    string roleID = ps["RoleID"];
        //    TRoleModule rm = (TRoleModule.moduleID == ps["moduleID"] & TRoleModule.roleID == ps["RoleID"]).ListFirst<TRoleModule>();
        //    bool[] permit = new bool[] { false, false, false, false, false };
        //    if (rm != null)
        //    {
        //        permit = UserUtil.BoolPermit(rm.Permit);
        //    }
        //    List<object> list = new List<object>();
        //    list.Add(new { Value = permit[0], Text = "创建" });
        //    list.Add(new { Value = permit[1], Text = "读取" });
        //    list.Add(new { Value = permit[2], Text = "更新" });
        //    list.Add(new { Value = permit[3], Text = "删除" });
        //    list.Add(new { Value = permit[4], Text = "审核" });
        //    return JSON.Serialize(list);
        //}
        //public string CheckModule(NameValueCollection ps)
        //{
        //    try
        //    {
        //        if (ps["check"] == "false")
        //        {
        //            (TRoleModule.moduleID == ps["moduleID"] & TRoleModule.roleID == ps["RoleID"]).Delete<TRoleModule>();
        //        }
        //        else if (ps["check"] == "true")
        //        {
        //            TRoleModule rm = new TRoleModule();
        //            rm.ModuleID = int.Parse(ps["moduleID"]);
        //            rm.RoleID = ps["RoleID"];
        //            rm.Permit = "00000";
        //            DBContext.Save(rm);
        //        }
        //        return JSON.ExtResult("true", "true");
        //    }
        //    catch
        //    {
        //        return JSON.ExtResult("false", "false");
        //    }
        //}
        //public string CheckPermit(NameValueCollection ps)
        //{
        //    try
        //    {
        //        TRoleModule t = (TRoleModule.moduleID == ps["moduleID"] & TRoleModule.roleID == ps["RoleID"]).ListFirst<TRoleModule>();
        //        if (t != null)
        //        {
        //            t.Permit = ps["indexs"];
        //            DBContext.Save(t);
        //        }
        //        return JSON.ExtResult("true", "true");
        //    }
        //    catch
        //    {
        //        return JSON.ExtResult("false", "false");
        //    }
        //}
        //public string ModuleTree(NameValueCollection ps)
        //{
        //    string roleID = ps["RoleID"];
        //    using (IConnectinContext cc = DBContext.Context1)
        //    {
        //        IList<TModule> list = (TModule.status > 0).List<TModule>();
        //        IList<TModule> Parent = list.AsQueryable().Where(c => c.Pid == 0).ToList();
        //        IList<VRoleModule> RoleModuleList = (VRoleModule.roleID == roleID).List<VRoleModule>();
        //        IList<ExtCheckTreeNode> tree = CreateModuleTree(list, Parent, RoleModuleList);
        //        return JSON.Serialize(tree).Replace("Checked", "checked");
        //    }
        //}
        //private IList<ExtCheckTreeNode> CreateModuleTree(IList<TModule> list, IList<TModule> Parent, IList<VRoleModule> RoleModuleList)
        //{
        //    IList<ExtCheckTreeNode> nodes = new List<ExtCheckTreeNode>();
        //    foreach (TModule t in Parent)
        //    {
        //        ExtCheckTreeNode node = new ExtCheckTreeNode();
        //        List<TModule> child = list.AsQueryable().Where(c => c.Pid == t.EntityID).ToList();
        //        if (child.Count > 0)
        //        {
        //            node.id = t.EntityID.ToString();
        //            node.text = t.NameCN;
        //            //node.SingleClickExpand = true;
        //            node.expanded = true;
        //            //if (t.Pid > 0) node.Checked = ThreeStateBool.True;
        //            IList<ExtCheckTreeNode> nodess = CreateModuleTree(list, child, RoleModuleList);
        //            node.children = CreateModuleTree(list, child, RoleModuleList);
        //            //node.Nodes.Add();
        //        }
        //        else
        //        {
        //            //RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        //            //int rowindex = sm.SelectedRows[0].RowIndex;
        //            node.leaf = true;
        //            node.id = t.EntityID.ToString();
        //            node.text = t.NameCN;
        //            //string iconFile = "/Ext/resources/images/Icons/" + t.NameEN + ".png";
        //            //if (File.Exists(HttpContext.Current.Server.MapPath(iconFile)))
        //            //    node.IconFile = iconFile;
        //            //node.SingleClickExpand = true;
        //            node.iconCls = "Kwan-icon-" + t.NameEN;
        //        }
        //        bool NodeChecked = false;
        //        if (RoleModuleList.Count > 0)
        //        {
        //            NodeChecked = RoleModuleList.AsQueryable().Where(c => c.ModuleNameEN.Equals(t.NameEN)).Count() > 0;
        //        }
        //        node.Checked = NodeChecked ? true : false;
        //        //root.Loader.Add(node);
        //        //ModuleTree.Root.Add(node);
        //        nodes.Add(node);
        //    }
        //    return nodes;
        //}
        //public string RoleTree(NameValueCollection ps)
        //{
        //    IList<TRole> list = new Expression().List<TRole>();
        //    IList<ClassTree> treeList = new List<ClassTree>();
        //    CreatedTree(treeList, null, list);
        //    return JSON.Serialize(treeList);
        //}
        //private void CreatedTree(IList<ClassTree> tree, ClassTree node, IList<TRole> parent)
        //{
        //    foreach (TRole p in parent)
        //    {
        //        node = SetNode(p, false);
        //        node.children = new List<ClassTree>();
        //        node.leaf = true;
        //        tree.Add(node);
        //    }
        //}
        //private ClassTree SetNode(TRole t, bool isLeaf)
        //{
        //    ClassTree node = new ClassTree();
        //    node.expanded = true;
        //    node.isChecked = false;
        //    node.id = t.EntityID.ToString();
        //    node.leaf = isLeaf;
        //    node.text = t.NameCN;
        //    return node;
        //}
        //#endregion

        //#region 员工
        //public string User(NameValueCollection ps)
        //{
        //    BaseFacade<TUser, VUser> facade = new BaseFacade<TUser, VUser>();
        //    facade.QueryBuilder = new UserQuery();
        //    if (!string.IsNullOrEmpty(ps["data"]))
        //    {
        //        string pwd = Format.CutString(ps["data"], "\"Password\":\"", "\"")[0];
        //        ps.Set("data", ps["data"].Replace("\"Password\":\"" + pwd, "\"Password\":\"" + MD5.Md5Encrypt(pwd)));
        //    }
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 宾客
        //public string Customer(NameValueCollection ps)
        //{
        //    if (!string.IsNullOrEmpty(ps["query"]))
        //    {
        //        ps.Set("query1", "NameCN=" + ps["query"]);
        //    }
        //    BaseFacade<TCustomer, VCustomer> facade = new BaseFacade<TCustomer, VCustomer>();
        //    facade.QueryBuilder = new CustomerQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 消费查询
        //public string Consume(NameValueCollection ps)
        //{
        //    if (string.IsNullOrEmpty(ps["query1"]))
        //    {
        //        ps.Set("query1", string.Format("tag=,{0},{1}", DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd")));
        //    }
        //    BaseFacade<TConsume, VConsume> facade = new BaseFacade<TConsume, VConsume>();
        //    facade.QueryBuilder = new ConsumeQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 结账单
        //public string Collection(NameValueCollection ps)
        //{
        //    if (string.IsNullOrEmpty(ps["query1"]))
        //    {
        //        ps.Set("query1", string.Format("tag=,{0},{1}", DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd")));
        //    }
        //    BaseFacade<TCollection, VCollection> facade = new BaseFacade<TCollection, VCollection>();
        //    facade.QueryBuilder = new CollectionQuery();
        //    string result = facade.Execute(ps);
        //    return result;
        //}
        //#endregion

        //#region 房态表
        //public string RoomStatus(NameValueCollection ps)
        //{
        //    string[] status = new string[] { "空洁房", "空脏房", "维修房", "住客房", "保留房" };
        //    var roomList = new Expression().List<VRoom>("Cid ASC");
        //    var roomClass = roomList.Distinct(p => p.ClassName, StringComparer.CurrentCultureIgnoreCase).ToList<VRoom>();
        //    List<VRoom> query = roomClass.Where(a => roomList.Any(b => b.Cid == a.Cid)).ToList();
        //    NameValueCollection nv = new NameValueCollection();
        //    query.FindAll(delegate(VRoom t)
        //    {
        //        if (string.IsNullOrEmpty(nv[t.ClassName]))
        //        {
        //            t.Deposit = 1;
        //            nv.Set(t.ClassName, "");
        //        }
        //        return true;
        //    });
        //    var queryRoom = from VRoom t in roomClass
        //                    from VRoom tt in roomList.Where(c => c.Cid == t.Cid)
        //                    select new
        //                    {
        //                        RoomNO = tt.RoomNO,
        //                        ClassName = tt.ClassName,
        //                        Id = "Room_" + tt.EntityID,
        //                        Price = tt.Price == 0 ? tt.ClassPrice : tt.Price,
        //                        Type = tt.ClassName,
        //                        Status = status[tt.Status],
        //                        CustomerName = tt.CustomerName,
        //                        IsComputer = tt.IsComputer,
        //                        IsMaQue = tt.IsMaQue,
        //                        IsFirst = tt.Deposit
        //                    };
        //    string result = JSON.Serialize(queryRoom);
        //    return result;
        //}
        //#endregion

        //#region CheckRoomStatus
        //public string CheckRoomStatus(NameValueCollection ps)
        //{
        //    string room_json = "false";
        //    string order_json = "false";
        //    string customer_json = "false";
        //    string leftPro_json = "false";
        //    string consume_json = "false";
        //    bool flag = false;
        //    if (!string.IsNullOrEmpty(ps["RoomID"]))
        //    {
        //        using (IConnectinContext cc = DBContext.Context1)
        //        {
        //            cc.BeginTransaction();
        //            VRoom room = (TRoom.entityID == int.Parse(ps["RoomID"])).ListFirst<VRoom>();
        //            if (room == null)
        //            {
        //                return JSON.ExtResult("false", "false");
        //            }
        //            if (room.Status == 3)
        //            {
        //                VOrder order = (VOrder.roomNO == room.RoomNO & VOrder.status == 1).ListFirst<VOrder>(VOrder.checkInDate.Desc);
        //                TCustomer customer = (TCustomer.entityID == order.CustomerID).ListFirst<TCustomer>();
        //                IList<TProduct> proList = new Expression().List<TProduct>(TProduct.cid.Asc);
        //                IList<TConsume> consumeList = (TConsume.orderID == order.EntityID & TConsume.status == 1).List<TConsume>(TConsume.type.Asc);

        //                cc.Commit();
        //                IList<TProduct> leftPro = proList.Where(a => !consumeList.Any(b => b.Item == a.NameCN && b.Type == 2)).ToList();

        //                room_json = JSON.Serialize(room);
        //                order_json = JSON.Serialize(order);
        //                customer_json = JSON.Serialize(customer);
        //                leftPro_json = JSON.Serialize(leftPro);
        //                consume_json = JSON.Serialize(consumeList);
        //            }
        //            flag = true;    //room不为null
        //        }
                
        //    }
        //    return ("{\"success\":" + flag.ToString().ToLower() + ",\"room\":" + room_json + ",\"order\":" + order_json + ",\"customer\":" + customer_json + ",\"leftPro\":" + leftPro_json + ",\"consume\":" + consume_json + "}");
        //}
        //#endregion

        #region 查询消费品
        public string QueryOrderProduct(NameValueCollection ps)
        {
            string pro_json = "false";
            bool flag = false;
            if (!string.IsNullOrEmpty(ps["orderID"]))
            {
                using (IConnectinContext cc = DBContext.Context1)
                {
                    cc.BeginTransaction();
                    int orderID = int.Parse(ps["orderID"]);
                    IList<TProduct> proList = new Expression().List<TProduct>(TProduct.cid.Asc);
                    IList<TConsume> consumeList = (TConsume.orderID == orderID & TConsume.status == 1).List<TConsume>(TConsume.type.Asc);
                    cc.Commit();
                    IList<TProduct> leftPro = proList.Where(a => !consumeList.Any(b => b.Item == a.NameCN && b.Type == 2)).ToList();

                    pro_json = JSON.Serialize(leftPro);
                    flag = true;
                }
            }
            return ("{\"success\":" + flag.ToString().ToLower() + ",\"data\":" + pro_json + "}");
        }
        #endregion

        #region 查询消费品
        public string QueryOrderConsume(NameValueCollection ps)
        {
            string consume_json = "false";
            bool flag = false;
            if (!string.IsNullOrEmpty(ps["orderID"]))
            {
                using (IConnectinContext cc = DBContext.Context1)
                {
                    cc.BeginTransaction();
                    int orderID = int.Parse(ps["orderID"]);
                    IList<TConsume> consumeList = (TConsume.orderID == orderID & TConsume.status == 1).List<TConsume>(TConsume.type.Asc);
                    cc.Commit();
                    consume_json = JSON.Serialize(consumeList);
                    flag = true;
                }
            }
            return ("{\"success\":" + flag.ToString().ToLower() + ",\"data\":" + consume_json + "}");
        }
        #endregion

        #region 查询消费品
        private double CountCheckOutRoomPrice()
        {

        }            
        public string CountCheckOut(NameValueCollection ps)
        {
            int orderID=int.Parse(ps["orderID"]);
            bool flag = false;

            string consume_json = "false";
            bool flag = false;
            if (orderID>0)
            {
                using (IConnectinContext cc = DBContext.Context1)
                {
                    cc.BeginTransaction();
                    VOrder order = (VOrder.EntityID == orderID & VOrder.status == 1).ListFirst<VOrder>(VOrder.checkInDate.Desc);
                    TCollection dpCL = (TCollection.orderID == orderID & TCollection.type == 1).ListFirst<TCollection>();
                    cc.Commit();
                    double roomPrice = order.CheckInRoomPrice;
                    double roomHalfPrice = room.HalfPrice > 0 ? room.HalfPrice : room.ClassHalfPrice;
                    double roomNightPrice = room.NightPrice > 0 ? room.NightPrice : room.ClassNightPrice;
                    double roomHourPrice = room.HourPrice > 0 ? room.HourPrice : room.ClassHourPrice;
                    double checkOutRoomPrice=0;
                    if (order.CheckInRoomPrice != order.CheckInPrice && order.CheckInType != 1)    //入住价格不等于房价
                    {
                        roomPrice = order.CheckInPrice;
                        roomHalfPrice = 0; roomNightPrice = 0;
                    }

                    if (order.CheckInType == 1)     //钟点房计算
                    {
                        roomHourPrice = order.CheckInPrice;
                        checkOutRoomPrice =
                            PriceManager.Instance.GetHourPrice(order.CheckInDate, DateTime.Now, roomPrice, roomHalfPrice, roomHourPrice);
                    }
                    else
                    {
                        checkOutRoomPrice =
                            PriceManager.Instance.GetFinalPrice(order.CheckInDate, DateTime.Now, roomPrice, roomHalfPrice, roomNightPrice);

                    }
                    
                    double proPrice = 0;
                    List<TConsume> proList = (TConsume.OrderID == orderID).List<TConsume>();
                    if (proList.Count > 0)
                    {
                        proList.FindAll(delegate(TConsume t)
                        {
                            if (t.EntityID != 0)
                            {
                                proPrice += t.Total * t.Nett;
                            }
                            return true;
                        });
                    }
                    double deposit = dpCL == null ? 0 : dpCL.CashPay + dpCL.PosPay;
                    double receivable = checkOutRoomPrice + proPrice;
                    //double payDisCount = (double)(((100m - Convert.ToDecimal(txtDisCount.Text)) / 100) * (decimal)receivable);
                    //txtReceivable.Text = receivable.ToString();
                    //txtPayDeposit.Text = deposit.ToString();
                    //txtPayDisCount.Text = payDisCount.ToString();
                    //double paid = receivable - payDisCount - deposit;
                    double paid = receivable - deposit;
                    
                    double change=0;
                    double cashPay=0;
                    double posPay=0;
                    if (paid < 0)
                    {
                        change = paid;
                        paid = 0;
                    }
                    flag = true;
                }
            }
            return ("{\"success\":" + flag.ToString().ToLower() + ",\"data\": [{\"Receivable:\"" + receivable + "\"PayDeposit:\"" + deposit + "\"Paid:\"" + paid + "\"Change:\"" + change + "\"CashPay:\"" + cashPay + "\"PosPay:\"" + posPay + "}]}");
        }
        #endregion        
    }
}
